package com.ruoyi.jacfile.minio;

import io.minio.MinioClient;
import io.minio.errors.MinioException;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MinioTest {
    public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException, XmlPullParserException {
        try {
            // 使用MinIO服务的URL，端口，Access key和Secret key创建一个MinioClient对象
            MinioClient minioClient = new MinioClient("http://192.168.15.53:9000", "minioadmin", "minioadmin");

             //检查存储桶是否已经存在
            boolean isExist = minioClient.bucketExists("pdf2020-07-07");
            if(isExist) {
                System.out.println("Bucket already exists.");
            } else {
                // 创建一个名为asiatrip的存储桶，用于存储照片的zip文件。
                System.out.println("Bucket is't exists.");
                return ;
            }
//            for(int i=1;i<2000;i++){
//                minioClient.removeBucket("aa"+i);
//            }


//            // 使用putObject上传一个文件到存储桶中。
//            InputStream object = minioClient.getObject("2020-06-18", "2020/06/18/470fc3b97f37373ed7378b0cd67a4ae5.png");
//            System.out.println("/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.");
        } catch(MinioException e) {
            System.out.println("Error occurred: " + e);
        }
    }
}
